// pages/page/huodong/yuozhi.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    everydayNewContent: [],//每日上新获取到的内容
    typeOfTea: [{//茶品的种类
      name: "乌龙茶",
      classify: "1",
    }, {
      name: "红茶",
      classify: "2",
    }, {
      name: "白茶",
      classify: "3",
    }, {
      name: "普洱",
      classify: "4",
    }, {
      name: "黑茶",
      classify: "5",
    }, {
      name: "黄茶",
      classify: "6",
    }, {
      name: "绿茶",
      classify: "7",
    }, {
      name: "花茶",
      classify: "8",
    }, {
      name: "茶器",
      classify: "9",
    }],
    classify:"3",
    selectTypePosition:0,
    color_52b318:"#52b318",
    color_5E5E5E:"#5E5E5E",
    color_FFFFFF:"#FFFFFF",
    typeOfTeaContent:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDataFromServiceOfEverydayNews();//获取每日上新数据
    this.getDataFromServiceOfTypeTea();//获取茶分类的数据
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("上拉触底事件");
    this.onloadTypeOfTea();// 茶叶种类商品列表上拉加载方法
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 茶叶种类商品列表上拉加载方法
   */
  onloadTypeOfTea:function(){
    this.getDataFromServiceOfTypeTea();//从服务器中获取分类信息
  },
  /**
   * 茶叶种类点击事件
   */
  typeOfTeaClck:function(event){
    console.log(event);
    this.setData({
      selectTypePosition:event.currentTarget.dataset.index,
      classify: event.currentTarget.dataset.classify,
      typeOfTeaContent:[],
    });
    this.getDataFromServiceOfTypeTea();//从服务器中获取分类信息
  },
  /**
   * 每日上新加载下一页
   */
  everydayNewsGetNext: function (event) {
    this.getDataFromServiceOfEverydayNews();
  },
  /**
   * 类型的上拉加载
   */
  typeOfTeaScrollOnload:function(event){
    console.log("类型的上拉加载");
    this.onloadTypeOfTea();// 茶叶种类商品列表上拉加载方法
  },
  /**
   * 从服务器中获取每日上新数据
   */
  getDataFromServiceOfEverydayNews: function () {
    var that = this;
    wx.request({
      url: "http://120.55.137.143:54321/service/teabubble/shop_pass_newBusiness?methods=getGoodsList",
      data: {
        "beginId": that.data.everydayNewContent.length,
        "count": 20,
        "queryType": 2,
      },
      header: {
        'content-type': 'application/json'
      },// 默认值
      success: function (res) {
        console.log(res.data);
        var content = that.data.everydayNewContent.concat(res.data.content);
        that.setData({
          everydayNewContent: content,
        });
      }
    })
  },
  /**
   * 从服务器中获取茶分类的数据
   */
  getDataFromServiceOfTypeTea: function () {
    var that = this;
    wx.request({
      url: "http://120.55.137.143:54321/service/teabubble/shop_paopao_goods?methods=getCPPGoodsList",
      data: {
        "beginId": that.data.typeOfTeaContent.length,
        "count": "20",
        "classify": that.data.classify,
        "status": "7",
      },
      success: function (res) {
        console.log("--------------------------------------------------");
        console.log(res.data);
        var content = that.data.typeOfTeaContent.concat(res.data.content);
        that.setData({
          typeOfTeaContent:content,
        });
      }
    })
  }
})